<script setup>
import NavBar from './components/NavBar.vue'
import { onMounted, onUnmounted, ref } from 'vue'

// 视差效果相关代码
const x = ref(0)
const y = ref(0)

const handleMouseMove = (e) => {
  // 计算鼠标位置的百分比
  const mouseXPercent = e.clientX / window.innerWidth
  const mouseYPercent = e.clientY / window.innerHeight
  
  // 计算移动距离（以像素为单位）
  const moveX = (mouseXPercent - 0.5) * 50 // 左右移动50px
  const moveY = (mouseYPercent - 0.5) * 50 // 上下移动50px
  
  x.value = moveX
  y.value = moveY
}

onMounted(() => {
  window.addEventListener('mousemove', handleMouseMove)
})

onUnmounted(() => {
  window.removeEventListener('mousemove', handleMouseMove)
})
</script>

<template>
  <div class="app">
    <!-- 导航栏 -->
    <NavBar />
    
    <!-- 视差背景 -->
    <div class="parallax-container">
      <div 
        class="parallax-bg" 
        :style="{ transform: `translate(${x}px, ${y}px)` }"
      ></div>
    </div>
    
    <!-- 主内容区 -->
    <main class="main-content">
      <router-view />
    </main>
  </div>
</template>

<style>
/* 全局样式变量 */
:root {
  --primary-color: #4CAF50;
  --primary-hover: #3d8b40;
  --text-primary: #333;
  --text-secondary: #666;
  --white: #ffffff;
  --light-gray: #f5f5f5;
  --radius: 12px;
  --transition: all 0.3s ease;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* 基础样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--white);
}

/* 应用容器 */
.app {
  min-height: 100vh;
  position: relative;
}

/* 视差背景容器 */
.parallax-container {
  position: relative;
  height: 400px;
  width: 100%;
  overflow: hidden;
  margin-top: 72px; /* 为导航栏腾出空间 */
}

/* 视差背景图片 */
.parallax-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 110%;
  height: 110%;
  background-image: url('@/assets/Hero.png');
  background-size: cover;
  background-position: center;
  filter: brightness(0.7);
  transition: transform 0.1s ease-out;
  z-index: 1;
}

/* 主内容区域 */
.main-content {
  position: relative;
  background-color: var(--white);
  z-index: 2;
  padding-top: 20px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .parallax-container {
    margin-top: 56px;
    height: 300px;
  }
}
</style>
